<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Make Controller Kit - Firmware API: Servo</title>
<link href="mt_doxygen.css" rel="stylesheet" type="text/css" />
<link href="../resources/mt_doxytabs.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.header {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12pt;
	color: #222222;
}
-->
</style>
</head>

<body>
<table width="800" border="0">
    <tr>
      <td colspan="3">
        <form method="get" action="http://www.google.com/search">
          <div align="right">
            <input type="text"   name="q" size="25"
              maxlength="255" value="" />
            <input type="submit" value="Search" />
            <input type="hidden" name="sitesearch" value="makingthings.com/ref/firmware/html" />
          </div>
        </form>
       </td>
    </tr>
    <tr>
      <td><div align="center"><a href="http://www.makingthings.com">
				<img src="../resources/logo_brown_medium.png" alt="MakingThings"
									width="200" height="78" border="0" align="middle" longdesc="http://www.makingthings.com" /></a></div></td>
				<td><div align="center" class="header">
      		Make Controller Kit <br />
          Firmware API
      </div></td>
      <td><div align="center"><a href="http://www.makezine.com">
					<img src="../resources/make_logo.png" alt="MAKE Zine" 
										width="164" height="73" border="0" align="middle" longdesc="http://www.makezine.com" /></a></div></td>
    </tr>
</table>
</body>
</html>
<!-- Generated by Doxygen 1.5.4 -->
<script type="text/javascript">
<!--
function changeDisplayState (e){
  var num=this.id.replace(/[^[0-9]/g,'');
  var button=this.firstChild;
  var sectionDiv=document.getElementById('dynsection'+num);
  if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
    sectionDiv.style.display='block';
    button.src='open.gif';
  }else{
    sectionDiv.style.display='none';
    button.src='closed.gif';
  }
}
function initDynSections(){
  var divs=document.getElementsByTagName('div');
  var sectionCounter=1;
  for(var i=0;i<divs.length-1;i++){
    if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
      var header=divs[i];
      var section=divs[i+1];
      var button=header.firstChild;
      if (button!='IMG'){
        divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
        button=document.createElement('img');
        divs[i].insertBefore(button,divs[i].firstChild);
      }
      header.style.cursor='pointer';
      header.onclick=changeDisplayState;
      header.id='dynheader'+sectionCounter;
      button.src='closed.gif';
      section.id='dynsection'+sectionCounter;
      section.style.display='none';
      section.style.marginLeft='14px';
      sectionCounter++;
    }
  }
}
window.onload = initDynSections;
-->
</script>
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="modules.html"><span>Modules</span></a></li>
    <li><a href="classes.html"><span>Data&nbsp;Structures</span></a></li>
    <li><a href="files.html"><span>Files</span></a></li>
    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
  </ul>
</div>
<h1>Servo<br>
<small>
[<a class="el" href="group___app_board.html">AppBoard</a>]</small>
</h1>The Servo Motor subsystem controls speed and position control for up to 4 standard servo motors.  
<a href="#_details">More...</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___servo.html#g8ecf12d7f9b6c7130cac1f0c33270e4b">Servo_SetActive</a> (int index, int state)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Lock or unlock the I/O lines used by the servos.  <a href="#g8ecf12d7f9b6c7130cac1f0c33270e4b"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___servo.html#g5cee903342f9a9f772713b4059ff911c">Servo_GetActive</a> (int index)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Check whether the I/O lines used by the servos are locked.  <a href="#g5cee903342f9a9f772713b4059ff911c"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___servo.html#g6fdf6eb917b9aa2a25939d9a44821b22">Servo_SetPosition</a> (int index, int position)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Set the position of the specified servo motor.  <a href="#g6fdf6eb917b9aa2a25939d9a44821b22"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___servo.html#g4a71ffa4eaba4813382dc5de22b7f74c">Servo_SetSpeed</a> (int index, int speed)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Set the speed at which a servo will move in response to a call to <a class="el" href="group___servo.html#g6fdf6eb917b9aa2a25939d9a44821b22" title="Set the position of the specified servo motor.">Servo_SetPosition()</a>.  <a href="#g4a71ffa4eaba4813382dc5de22b7f74c"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___servo.html#g214b93c5b01fa4e91a9d1a06f606a342">Servo_GetPosition</a> (int index)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Read the current position of a servo motor.  <a href="#g214b93c5b01fa4e91a9d1a06f606a342"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___servo.html#g611ac83ea6ee2bc174cc20bf51cbeb5d">Servo_GetSpeed</a> (int index)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Get the speed at which a servo will move in response to a call to <a class="el" href="group___servo.html#g6fdf6eb917b9aa2a25939d9a44821b22" title="Set the position of the specified servo motor.">Servo_SetPosition()</a>.  <a href="#g611ac83ea6ee2bc174cc20bf51cbeb5d"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
The Servo Motor subsystem controls speed and position control for up to 4 standard servo motors. 
<p>
Standard servos have a range of motion of approximately 180 degrees, although this varies from motor to motor. Be sure to plug in the connector with the correct orientation with regard to the GND/5V signals on the board.<p>
Because not all servo motors are created equal, and not all of them can be safely driven across all 180 degrees, the default (safe) range of motion is from values 0 to 1023. The full range of motion is from -512 to 1536, but use this extra range cautiously if you don't know how your motor can handle it. A little gentle experimentation should do the trick.<p>
You can also specify the speed with which the motors will respond to new position commands - a high value will result in an immediate response, while a lower value can offer some smoothing when appropriate. <hr><h2>Function Documentation</h2>
<a class="anchor" name="g5cee903342f9a9f772713b4059ff911c"></a><!-- doxytag: member="servo.c::Servo_GetActive" ref="g5cee903342f9a9f772713b4059ff911c" args="(int index)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Servo_GetActive           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>index</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Check whether the I/O lines used by the servos are locked. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>index</em>&nbsp;</td><td>An integer specifying which servo (0-3). </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>State - 1 (active) or 0 (inactive). </dd></dl>

<p>Definition at line <a class="el" href="servo_8c-source.html#l00155">155</a> of file <a class="el" href="servo_8c-source.html">servo.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g214b93c5b01fa4e91a9d1a06f606a342"></a><!-- doxytag: member="servo.c::Servo_GetPosition" ref="g214b93c5b01fa4e91a9d1a06f606a342" args="(int index)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Servo_GetPosition           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>index</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Read the current position of a servo motor. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>index</em>&nbsp;</td><td>An integer specifying which servo (0 - 3). </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>The position (0 - 1023), or 0 on error. </dd></dl>

<p>Definition at line <a class="el" href="servo_8c-source.html#l00232">232</a> of file <a class="el" href="servo_8c-source.html">servo.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g611ac83ea6ee2bc174cc20bf51cbeb5d"></a><!-- doxytag: member="servo.c::Servo_GetSpeed" ref="g611ac83ea6ee2bc174cc20bf51cbeb5d" args="(int index)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Servo_GetSpeed           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>index</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Get the speed at which a servo will move in response to a call to <a class="el" href="group___servo.html#g6fdf6eb917b9aa2a25939d9a44821b22" title="Set the position of the specified servo motor.">Servo_SetPosition()</a>. 
<p>
Read the value previously set for the speed parameter. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>index</em>&nbsp;</td><td>An integer specifying which servo (0 - 3). </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>The speed (0 - 1023), or 0 on error. </dd></dl>

<p>Definition at line <a class="el" href="servo_8c-source.html#l00247">247</a> of file <a class="el" href="servo_8c-source.html">servo.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g8ecf12d7f9b6c7130cac1f0c33270e4b"></a><!-- doxytag: member="servo.c::Servo_SetActive" ref="g8ecf12d7f9b6c7130cac1f0c33270e4b" args="(int index, int state)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Servo_SetActive           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>index</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>state</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Lock or unlock the I/O lines used by the servos. 
<p>
Sets whether the specified Servo I/O is active. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>index</em>&nbsp;</td><td>An integer specifying which servo (0 - 3). </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>state</em>&nbsp;</td><td>An integer specifying the active state - 1 (active) or 0 (inactive). </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Zero on success. </dd></dl>

<p>Definition at line <a class="el" href="servo_8c-source.html#l00119">119</a> of file <a class="el" href="servo_8c-source.html">servo.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g6fdf6eb917b9aa2a25939d9a44821b22"></a><!-- doxytag: member="servo.c::Servo_SetPosition" ref="g6fdf6eb917b9aa2a25939d9a44821b22" args="(int index, int position)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Servo_SetPosition           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>index</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>position</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Set the position of the specified servo motor. 
<p>
Most servos like to be driven within a "safe range" which usually ends up being somewhere around 110-120 degrees range of motion, or thereabouts. Some servos don't mind being driven all the way to their 180 degree range of motion limit. With this in mind, the range of values you can send to servos connected to the Make Controller Kit is as follows:<ul>
<li>Values from 0-1023 correspond to the normal, or "safe", range of motion.</li><li>You can also send values from -512 all the way up to 1536 to drive the servo through its full range of motion.</li></ul>
<p>
Note that it is sometimes possible to damage your servo by driving it too far, so proceed with a bit of caution when using the extended range until you know your servos can handle it.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>index</em>&nbsp;</td><td>An integer specifying which servo (0 - 3). </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>position</em>&nbsp;</td><td>An integer specifying the servo position (0 - 1023). </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>status (0 = OK). </dd></dl>

<p>Definition at line <a class="el" href="servo_8c-source.html#l00180">180</a> of file <a class="el" href="servo_8c-source.html">servo.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g4a71ffa4eaba4813382dc5de22b7f74c"></a><!-- doxytag: member="servo.c::Servo_SetSpeed" ref="g4a71ffa4eaba4813382dc5de22b7f74c" args="(int index, int speed)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Servo_SetSpeed           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>index</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>speed</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Set the speed at which a servo will move in response to a call to <a class="el" href="group___servo.html#g6fdf6eb917b9aa2a25939d9a44821b22" title="Set the position of the specified servo motor.">Servo_SetPosition()</a>. 
<p>
Higher values will result in a more immediate response, while lower values will more slowly step through all the intermediate values, achieving a smoother motion. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>index</em>&nbsp;</td><td>An integer specifying which servo (0 - 3). </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>speed</em>&nbsp;</td><td>An integer specifying the servo speed (0 - 1023). </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>status (0 = OK). </dd></dl>

<p>Definition at line <a class="el" href="servo_8c-source.html#l00209">209</a> of file <a class="el" href="servo_8c-source.html">servo.c</a>.</p>

</div>
</div><p>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Make Controller Kit</title>
<style type="text/css">
<!--
.footer {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9pt;
	color: #999999;
}
-->
</style>
</head>

<body>
<hr size="1">
<div>
  <p class="footer">The Make Controller Kit is an open source project maintained by <a href="http://www.makingthings.com">MakingThings</a>.<br />
    MakingThings code is released under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">Apache 2.0 license</a>.<br />
    Bug tracker, development wiki and status can be found at <a href="http://dev.makingthings.com">http://dev.makingthings.com</a>.<br />
		This document was last updated on 5 Dec 2007.
</p>
</div>
<!-- Google Analytics Code -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-769030-1";
urchinTracker();
</script>
</body>
</html>
